using NUnit.Framework;

namespace ValidationFramework.Tests
{
	[TestFixture]
	public class ValidatableCollectionTest
	{
		public class NotifyValidatableBaseItem : NotifyValidatableBase
		{
			private string stringData;

			public NotifyValidatableBaseItem()
			{
				PropertyValidationManager.ValidateAll();
			}
			[RequiredStringRule]
			public string StringData
			{
				get
				{
					return stringData;
				}
				set
				{
					stringData = value;
					NotifyAndValidate("StringData");
				}
			}
		}
		[Test]
		public void ValidatableCollectionIsValidTest()
		{
			var col = new ValidatableCollection<NotifyValidatableBaseItem>();

			Assert.IsTrue(col.IsValid);
			Assert.AreEqual(col.ValidationMessages.Count, 0);
			var item = new NotifyValidatableBaseItem();
			col.Add(item);
			Assert.IsFalse(col.IsValid);
			Assert.AreEqual(col.ValidationMessages.Count, 1);
			item.StringData = "asas";
			Assert.IsTrue(col.IsValid);
			Assert.AreEqual(col.ValidationMessages.Count, 0);
		}
	}
}